Page({
    data: {
        value : '' ,
        id : '' ,
        type : 0
    },

    onLoad: function (opt) {
        console.log(opt)
        this.setData({
            id : opt.id ,
            type : opt.type
        })
    },

    xInput: function (e) {
        let that = this
        let value = e.detail.value
        that.setData({
            value: value
        })
    },

    xSub: function () {
        let that = this
        let value = that.data.value
        let id = that.data.id
        if (value === '') {
            wx.showToast({
                title: '请输入内容',
                icon: 'none'
            })
        } else {
            let _dataObj = {
                to_openid: id,
                message_type: 1,
                business_type: 6,
                content: {
                    title: value,
                    content: {
                        text: value
                    }
                }
            }
            wx.cloud.callFunction({
                name: 'consulting_message',
                data: {
                    action: "send_message",
                    dataObj: _dataObj
                }
            }).then(res => {
                wx.showToast({
                    title: '发送成功',
                    icon: 'none' ,
                    success: () => {
                        that.setData({
                            xDefaultValue: ''
                        })
                        setTimeout( () => {
                            wx.navigateBack({
                                delta: -1,
                            })
                        } , 2000)
                    }
                })
            })
        }
    },

    xErrorBack : function () {
        let that = this
        let id = that.data.id
        wx.cloud.callFunction({
            name: 'digital_therapy',
            data: {
                action: "is_audit_fail",
                _id: id
            }
        }).then(res => {
            wx.showToast({
                title: '正在为您跳转',
                icon: 'none',
                success : () => {
                    setTimeout( () => {
                        wx.navigateBack({
                            delta: -1,
                        })
                    } , 1000)
                }
            })
        })
    }
})